package wails_utils

import (
	"gitee.com/xgh2012/wails_common/wails_apps"
	"github.com/dgrijalva/jwt-go"
	"time"
)

func GetJwtToken(name string) string {
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		"name": name,
		"exp":  time.Now().Unix() + 9999999999,
		"iss":  "xgh",
	})
	str, _ := token.SignedString(wails_apps.JwtTokenKey)
	return str
}

func ParseJwtToken(tokenString string) (string, error) {
	token, err := jwt.Parse(tokenString, func(t *jwt.Token) (any, error) {
		return wails_apps.JwtTokenKey, nil
	})
	if err != nil {
		return "", err
	}
	return token.Claims.(jwt.MapClaims)["name"].(string), nil
}
